package com.company.manage.system.dao;

import com.company.manage.common.persistence.HibernateDao;
import com.company.manage.system.entity.RolePermission;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by HuangYong on 2016/1/22.
 * desc:角色权限DAO
 */
@Repository
public class RolePermissionDao extends HibernateDao<RolePermission,Integer> {
    private static final String TAG = "RolePermissionDao";

    /**
     * 查询角色拥有的权限的id
     * @param roleId
     * @return
     */
    public List<Integer> findPermissionIds(Integer roleId){
        String hql = "select rp.permission.id from RolePermission rp where rp.role.id = ?0 ";
        Query query = createQuery(hql,roleId);
        return query.list();
    }

    /**
     * 删除角色权限
     * @param roleId 角色id
     * @param permissionId 权限id
     */
    public void deleteRolePermission(Integer roleId,Integer permissionId){
        String hql = "delete RolePermission rp where rp.role.id = ?0 and rp.permission.id = ?1 ";
        batchExecute(hql,roleId,permissionId);
    }
} 